package com.easyhuan.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.easyhuan.dao.GoodsUtil;
import com.easyhuan.pojo.Goods;
import com.easyhuan.util.HibernateUtil;
import com.opensymphony.xwork2.ActionSupport;

public class DeleteGoods extends ActionSupport {
	private String msg;

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	@Override
	public String execute() throws Exception {
		GoodsUtil util = new GoodsUtil();
		Session session = HibernateUtil.getHibernateSession();
		Transaction transaction = session.beginTransaction();
		HttpServletRequest request = ServletActionContext.getRequest();
		try {
			String id = request.getParameter("id");
			System.out.println("id:" + id);
			Goods goods = util.selectGoodsById(session, id);
			util.deleteGoods(session, transaction, goods);
			msg = "删除成功!";

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			msg = "删除出错！";
			return ERROR;
		}
	}
}
